package com.ibeetl.admin.core.dao;

import java.util.List;

import org.beetl.sql.core.annotatoin.Param;
import org.beetl.sql.core.annotatoin.Sql;
import org.beetl.sql.core.annotatoin.SqlResource;
import org.beetl.sql.core.mapper.BaseMapper;
import org.beetl.sql.core.engine.PageQuery;

import  com.ibeetl.admin.core.entity.*;

/**
 * 点赞 Dao
 */
@SqlResource("core.coreZan")
public interface CoreZanDao extends BaseMapper<CoreZan>{
    public PageQuery<CoreZan> queryByCondition(PageQuery query);
    public void batchDelCoreZanByIds( List<Long> ids);
    
    //获取某个文章的点赞数
    @Sql("select sum(per) from core_zan z where z.article_id = ?")
    public Integer getZanByArticleId(@Param(value="article_id")Long articleId);
    //获取某个文章的点赞数
    @Sql("select sum(per) from core_zan z where z.article_id = ? and z.type = ?")
    public Integer getZanByArticleIdAndType(@Param(value="article_id")Long articleId,@Param(value="type")String type);
  //获取某个用户对某个文章某个类型的点赞数
    @Sql("select sum(per) from core_zan z where z.article_id = ? and z.type = ? and z.user_id = ?")
    public Integer getZanByArticleIdAndType(@Param(value="article_id")Long articleId,@Param(value="type")String type,@Param(value="userId")Long userId);
    
    //某个时间段IP地址的点赞数
    @Sql("select sum(per) from core_zan z where z.article_id = ? and z.create_time > ? and ip = ? and type = ?")
    public Integer validateZan(@Param(value="article_id")Long articleId, @Param(value="create_time")String createTime, @Param(value="ip")String ip, @Param(value="type")String type);
    
    //某个时间段IP地址的点赞数
    @Sql("select sum(per) from core_zan z where z.article_id = ? and z.create_time > ? and ip = ? and type = ? and user_id = ?")
    public Integer validateZan(@Param(value="article_id")Long articleId, @Param(value="create_time")String createTime, @Param(value="ip")String ip, @Param(value="type")String type, @Param(value="userId")Long userId);
}